package com.beilang.base.util;

import com.beilang.hotline.telrecord.to.SearchTO;

import java.util.Date;
import java.util.Calendar;
import java.util.Random;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;

public class ReportUtil {
    public static final String REPLY_DES = "处理";
    public static final String REPLYBY_DESC = "处理人";
    public static final String REPLYTIME_DESC = "处理时间";
    public static final String REPLYCONTENT_DESC = "处理内容";
    public static final String REPLYREASON_DESC = "处理原因";
    public static final String RECORDTIME_DESC = "来电时间";
    public static final String COMPANY_DESC = "企业";
    public static final String IDNO_DESC = "ID号";
    public static final String NAME_DESC = "姓名";
    public static final String SEX_DESC = "性别";
    public static final String RECORDNUMBER_DESC = "来电电话";
    public static final String SYSTEM_DESC = "系统";
    public static final String MODULE_DESC = "模块";
    public static final String ISSUE_DESC = "类别";
    public static final String TITLE_DESC = "标题";
    public static final String RECORDREMARKS_DESC = "问题描述及回复";
    public static final String RECORDREASON_DESC = "问题原因";
    public static final String CREATOR_DESC = "创建人";
    public static final String STATUS_DESC = "是否关闭";
    public static final String CURRENTOIC_DESC = "当前处理人";

    
       public String getTempFileName(String extension) {
        Date cur = new Date();
        Calendar cld = Calendar.getInstance();
        cld.setTime(cur);
        int mth = cld.get(Calendar.MONTH) + 1;
        String nowStr = cld.get(Calendar.YEAR) + "" + mth + cld.get(Calendar.DATE) + cld.get(Calendar.HOUR) + cld.get(Calendar.MINUTE) + cld.get(Calendar.SECOND);
        Random rdm = new Random();
        String rdmNum = String.valueOf(rdm.nextInt());
        return nowStr + rdmNum + extension;
    }

    public String deNull(Object s) {
        if (s == null) {
            return "";
        } else {
            return s.toString();
        }
    }

    public int getColumnSize(SearchTO searchTO) {
          int i = 0;
          if ("Y".equals(searchTO.getRecordTimeSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getCompanyIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getRecordIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getPersonIdSelected())) {
              i = i + 2;
          }
          if ("Y".equals(searchTO.getTelIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getSysIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getModuleIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getIssueIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getTitleIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getRemarksIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getReasonIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getCreatorIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getStatusIdSelected())) {
              i = i + 1;
          }
          if ("Y".equals(searchTO.getCurrentOwnerSelected())) {
              i = i + 1;
          }
          return i;

      }

     public byte[] readByteArrayOfSpecifiedFile(String fileName) throws IOException {
        FileInputStream fis = new FileInputStream(fileName);
        ByteArrayOutputStream fileByteStream = new ByteArrayOutputStream();
        int ch;
        while ((ch = fis.read()) != -1) {
            fileByteStream.write(ch);
        }
        fis.close();
        try {
            byte[] result = fileByteStream.toByteArray();
            return result;
        }
        finally {
            fileByteStream.close();
        }
    }

    public  String getSize(long i){
           BigDecimal result1 = null;
           String result = "";
           BigDecimal b = new BigDecimal(1024);
           BigDecimal length = new BigDecimal(i);

           if (length.compareTo(b) < 0) {
               result1 = b;
               result1 = result1.setScale(2, BigDecimal.ROUND_HALF_UP);
               result = result1 + "字节(Bytes)";
           } else if (length.compareTo(b.multiply(b)) < 0 && (length.compareTo(b) >= 0)) {
               result1 = length.divide(b);
               result1 = result1.setScale(2, BigDecimal.ROUND_HALF_UP);
               result = result1 + "千字节(KB)";
           } else if (length.compareTo(b.multiply(b)) > 0) {
               result1 = length.divide(b.multiply(b));
               result1 = result1.setScale(2, BigDecimal.ROUND_HALF_UP);
               result = result1 + "兆(M)";
           }

           return result;
       }
    
    
}
